#include "type.h"

/* UART0 power control */
#define PCUART0_POWERON (1 << 3)

#define IER_RBR     0x01
#define IER_THRE    0x02
#define IER_RLS     0x04

#define IIR_PEND    0x01
#define IIR_RLS     0x03
#define IIR_RDA     0x02
#define IIR_CTI     0x06
#define IIR_THRE    0x01
#define IIR_DISABLED 0x00

#define LSR_RDR     0x01
#define LSR_OE      0x02
#define LSR_PE      0x04
#define LSR_FE      0x08
#define LSR_BI      0x10
#define LSR_THRE    0x20
#define LSR_TEMT    0x40
#define LSR_RXFE    0x80

#define WLS_8BIT    0x03
#define DIVISOR_LATCH_ACCESS    (1 << 7)
#define UART_PRESCALER          16
#define LATCH_REGISTER_DIVIDER  256

#define FIFO_ENABLE             (1 << 0)
#define FIFO_RX_RESET           (1 << 1)
#define FIFO_TX_RESET           (1 << 2)

#define RX_LINE_INT             (1 << 2)
#define RX_DATA_AV_INT          (1 << 0)

#define IIR_PENDING             (1 << 0)

void uart_init(uint32_t baudrate);
void uart_read_byte(uint8_t *data);
void uart_send_byte(uint8_t data);
void uart_send_str(uint8_t *data);
void ui_printf(int8_t *fmt, ...);
void uart_uitoa(uint32_t number, int8_t* string);
void uart_itoa(int32_t number, int8_t* string);
void uart_xtoa(uint8_t number, int8_t* string);

void uart0_isr(void);

